package com.bsj.travel.device.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.bsj.travel.def.global.JsonResult;
import com.bsj.travel.def.global.JsonResultEnum;
import com.bsj.travel.def.monitor.tdengine.SuperTable;
import com.bsj.travel.device.service.TableTDengineService;
import com.bsj.travel.mapper.tdengine.TableTDengineMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLException;

/***
 * @description TableTDengineServiceImpl
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/2/21 19:31
 **/
@Service
@DS("slave")
public class TableTDengineServiceImpl implements TableTDengineService {

    @Resource
    private TableTDengineMapper tableTDengineMapper;

    /**
     * 创建超级表
     *
     * @param jsonResult
     * @return com.bsj.travel.def.global.JsonResult
     * @author ljx
     * @time 2024/2/21 19:32
     */
    @Override
    public JsonResult createSuperTable(JsonResult jsonResult) {
        if (jsonResult.getCode() == JsonResultEnum.SUCCESS.getCode()) {
            SuperTable superTable = new SuperTable();
            try {
                String productKey = (String) jsonResult.getData();
                superTable.transLogSuperTs(productKey);
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            }
            tableTDengineMapper.createSuperTable(superTable);
            return JsonResult.success();
        } else {
            return jsonResult;
        }
    }

}
